package com.czk.queue;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @Author:ChenZhangKun
 * @Date: 2023/7/11 12:15
 */
public class QueueImpStack<T> {
    private Queue<T> queue;
    private Queue<T> tempQueue;

    public QueueImpStack(LinkedList<T> queue, LinkedList<T> tempQueue) {
        this.queue = queue;
        this.tempQueue = tempQueue;
    }

    public void push(T t){
        queue.offer(t);
    }

    public T pop(){
        if (queue.isEmpty()){
            throw new RuntimeException("没有元素");
        }
        while (queue.size()>1){
            tempQueue.offer(queue.poll());
        }
        T t = queue.poll();
        Queue<T> temp=queue;
        queue=tempQueue;
        tempQueue=temp;
        return t;
    }

    
}

